package com.risen.test.controller;

import com.risen.test.pojo.User;
import com.risen.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther lmj
 * @date 2019/7/30
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/selectByPrimaryKey/{uuid}")
    public User selectByPrimaryKey(@PathVariable int uuid){
        User user = userService.selectByPrimaryKey(uuid);
        return user;
    }

    @RequestMapping("/insert")
    public int insert(@RequestBody User user){
        int insert = userService.insert(user);
        return insert;
    }

    @RequestMapping("/selectAll")
    public Map<String,Object> selectAll(){
        List<User> users = userService.selectAll();
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",1000);
        map.put("data",users);
        return map;
    }

    /**
     * 登录index页面
     */
    @RequestMapping("/index")
    public String toIndex(){
        return "WeAdmin/index";
    }
}
